package com.mercator.client.graph;

import java.util.Collection;
import java.util.Iterator;

import org.vaadin.gwtgraphics.client.DrawingArea;
import org.vaadin.gwtgraphics.client.Shape;

public abstract class DContainer <T extends Comparable<? super T>, N extends GNode<T,N, ? extends Shape> & Drawable,  C  extends Container<T, N>> implements Drawable , Iterable< N>{ 
	
	protected C container;
	protected NodeFactory<T,N> factory;
	protected DrawingArea canvas;
	protected MapName NAME;
	public abstract void unselectAll();

	public abstract void updateSelected();

	public DContainer(DrawingArea canvas){
		this.canvas =canvas;
	}
	
	public C getContainer(){
		return container;
	}
	
	public void addEdge(T w, T v){
		container.addEdge(w, v);
	}

	public String toString(){
		return container.toString();
	}
	public void remove(T t){
		container.remove(t);
	}

	public Iterator<N> iterator(){
		return container.iterator();
	}


	public Iterable<T> getVals(){
		return container.getVals();
	}

	public Collection<N> getCol(){
		return container.getCol();
	}
	
	public Collection<T> getValCol(){
		return container.getValCol();
	}

	public Iterable<? extends N> getNodes(){
		return container.getNodes();
	}

	public void connect(T elem1, T elem2){
		container.connect(factory.create(elem1), factory.create(elem2));
	}

	public void  connect(N elem1, N elem2){
		container.connect(elem1, elem2);
	}

	public void removeAll(){
		container.removeAll();
	}

	public void addAll(Collection<T> g){
		for(T t: g)
			container.add(factory.create(t));
	}
	
	public void addAllNodes(Collection<N> g){
		container.addAll(g);
	}
	
	public void add(N n){
		container.add(n);
	}
	
		
	
	public void add(T t){
		container.add(factory.create(t));
	}
	
	public N find(N n){
		return container.find(n);
	}
	
	public N find(T n){
		return container.find(n);
	}
	
	public abstract MapName getName();
	
	public abstract class NodeFactory<E extends Comparable<? super E>, A extends GNode<E,? super A, ? extends Shape> & Drawable>{
		public abstract N create(T t);
	}

	

}